package com.nine.system.controller;

import cn.dev33.satoken.annotation.SaCheckRole;
import com.nine.common.entity.ChangeForm;
import com.nine.common.entity.ChangeInfoVO;
import com.nine.common.entity.EngineerForm;
import com.nine.system.service.EngineerService;
import com.nine.common.tool.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description:
 * @ClassName: EngineerController
 * @Author: luodeng
 * @Date: 2023/6/7 10:33
 * @Version: 1.0
 */
@Api(tags = "工程师Api",description = "工程师有关的api")
@RestController
@RequestMapping("/engineer")
public class EngineerController {

    @Autowired
    private EngineerService engineerService;


    @SaCheckRole("101")
    @ApiOperation(value = "对工程师进行禁用or启用")
    @ApiImplicitParams({
            @ApiImplicitParam(value="工程师id",name="id",dataType="String",dataTypeClass = String.class, paramType = "query"),
            @ApiImplicitParam(value="是否启用账号(0禁用 1启用)",name="isEnabled",dataType="String",dataTypeClass = String.class, paramType = "query")
    })
    @PutMapping("/{id}/setEnabled/{isEnabled}")
    public ResponseResult setEngineerEnabled(@PathVariable Long id, @PathVariable Integer isEnabled) {
        return engineerService.updateEngineerIsEnabled(id, isEnabled);
    }

    @ApiOperation(value = "获取所有工程师(分页)")
    @GetMapping("/getAll")
    public ResponseResult getAll(int page,int limit){
        return engineerService.getAll(page,limit);
    }


    @GetMapping("/{id}")
    public ResponseResult getOne(@PathVariable Long id){
        return engineerService.getOne(id);
    }


    @ApiOperation(value = "根据条件筛选相应的工程师")
    @ApiImplicitParams({
            @ApiImplicitParam(value="工程师姓名",name="engineerName",dataType="String",dataTypeClass = String.class, paramType = "query"),
            @ApiImplicitParam(value="省份",name="engineerProvince",dataType="String",dataTypeClass = String.class, paramType = "query"),
            @ApiImplicitParam(value="市区",name="engineerCity",dataType="String",dataTypeClass = String.class, paramType = "query"),
            @ApiImplicitParam(value="区县",name="engineerArea",dataType="String",dataTypeClass = String.class, paramType = "query"),
            @ApiImplicitParam(value="手机号",name="engineerPhone",dataType="String",dataTypeClass = String.class, paramType = "query")
    })
    @PostMapping ("/find")
    public ResponseResult getSome(@RequestParam("engineerName") String engineerName,
                                  @RequestParam("engineerProvince")String engineerProvince,
                                  @RequestParam("engineerCity")String engineerCity,
                                  @RequestParam("engineerArea")String engineerArea,
                                  @RequestParam("engineerPhone")String engineerPhone,
                                  @RequestParam("page")int page,
                                  @RequestParam("limit")int limit){
        return engineerService.getSome(engineerName,engineerProvince,engineerCity,engineerArea,engineerPhone,page,limit);
    }

    @ApiOperation(value = "工程师修改个人信息")
    @ApiImplicitParam(value = "更新后的工程师个人信息",name = "changeInfoVO",dataType="ChangeInfoVO",dataTypeClass = ChangeInfoVO.class, paramType = "body")
    @PostMapping("/getChange")
    public ResponseResult getChange(@RequestBody ChangeInfoVO changeInfoVO){
        return engineerService.changeInfo(changeInfoVO);
    }

    @ApiOperation(value = "根据token返回当前工程师地域信息")
    @GetMapping("/getEngineerAddress")
    public ResponseResult getEngineerAddress(){
        return engineerService.getAddressByToken();
    }


    @ApiOperation(value = "根据token返回当前工程师个人全部信息")
    @GetMapping("/getMyInfo")
    public ResponseResult getMyInfo(){
        return engineerService.getMyInfo();
    }

}
